<!--
 * @Description:5秒发送短信
 * @Author: Sun
 * @Date: 2019-07-01 20:05:50
 * @LastEditors: Sun
 * @LastEditTime: 2019-07-13 17:12:01
 -->
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>5秒发送短信</title>
	<style>

	</style>
	<script>
		window.onload = function () {
			var btn = document.getElementById("btn")
			var count = 5;
			var timer = null;
			btn.onclick = function () {
				var that = this
				clearInterval(timer);
				this.disabled=true;
				timer = setInterval(sendText, 1000)
				function sendText() {
					count--;
					if (count >= 0) {
						console.log("pppp")
						that.innerHTML = `还剩下${count}秒`;
					} else {
						that.innerHTML = "重新发送短信";
						that.disabled = false;
						clearInterval(timer);
						count = 5
					}
				}
			}


		}
	</script>
</head>

<body>
	<input type="text">
	<button id="btn">点击发送短信</button>
</body>

</html>